//
//  SupDetailViewController.m
//  艾听歌
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SupDetailViewController.h"
#import "SupDetailTableViewCell.h"
#import "SlideViewController.h"

#import "SupdetailModel.h"

@interface SupDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *dataArray;

@end

@implementation SupDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor whiteColor];
    self.view.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9c9c9c);
    self.navigationController.navigationBar.dk_barTintColorPicker = DKColorPickerWithRGB(0xFF6EB4, 0x9C9C9C);
//    NSLog(@"%@", self.itemId);
    self.dataArray = [NSMutableArray array];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[SupDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self getdata];
    
}

- (void)getdata
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *str = [NSString stringWithFormat:@"http://api.dongting.com/song/singer_classify/%@?app=ttpod&v=v9.0.1.2016050614&user_id=0&mid=iPhone7%%2C2&f=f320&s=s310&imsi=&hid=&splus=9.3.1&active=1&net=2&openudid=5e6106cc8d5bcf35f60a2997c79a00bb5a7c631f&idfa=ABDADD65-0877-4840-B14F-DFC8D1114AB0&utdid=VzR0dwnWYs8DANbYJ8SsFzOU&alf=(null)&bundle_id=com.ttpod.music&latitude=-1&longtitude=-1&access_token=(null)&vc=9000100", self.itemId];
    [manager GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        

        
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSArray *array = dic[@"singers"];
        for (NSDictionary *smallDic in array) {
            SupdetailModel *model = [[SupdetailModel alloc] init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.dataArray addObject:model];
        

        }
     
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SupDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9c9c9c);
    SupdetailModel *model = self.dataArray[indexPath.row];
    [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];
    cell.headerImage.layer.cornerRadius = 30;
    cell.headerImage.layer.masksToBounds = YES;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.name.text = model.name;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SlideViewController *singerVC = [[SlideViewController alloc] init];
    SupdetailModel *model = self.dataArray[indexPath.row];

    singerVC.supModel = model;
    
    [self.navigationController pushViewController:singerVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
